import scipy.signal
def plotspec(x, Ts):
fig = figure()
ax1 = fig.add_subplot(211)
ax1.plot(x)
q = fft.fft(x)
ax2 = fig.add_subplot(212)
ax2.plot(fft.fftfreq(len(x), Ts), abs(q))
time = 3.0
Ts = 1.0/20000.0
b = scipy.signal.remez(100, [0, 0.145, 0.15, 0.2, 0.205, 0.5], [0, 1, 0])
n = 0.25 * random.normal(0,1,time/Ts)
x = scipy.signal.lfilter(b, 1, 2*random.normal(0,1,time/Ts))
y = scipy.signal.lfilter(b, 1, x+n)
yx = scipy.signal.lfilter(b,1,x)
yn = scipy.signal.lfilter(b, 1, n)
z = yx+yn
plotspec(x, Ts)
plotspec(z, Ts)
#diffzy = max(abs(z-y))
#snrinp = pow(x)/pow(n)
#snrout=pow(yx)/pow(yn)